Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

C Programming interview questions


Declarations and Initializations

Ques:Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1

Ans.rem = modf(3.14, 2.1).

What are the types of linkages

  1. External Linkage: means global, non-static variables and functions.
  2. Internal Linkage: means static variables and functions with file scope.
  3. None Linkage-> means Local variables.

Is there any difference between following declarations?

  1. extern int fun:
  2. int fun();

No difference, except extern int fun(); is probably in another file.

How would you round off a value from 1.66 to 2.0

" ceil(1.66)" .

Which of the following is not user defined data type?

long int l = 2.35 .

Is the following statement a declaration or definition?extern int i;

Declaration

Identify which of the following are declarations

  1. extern int x
  2. float square ( float x ) { ... }
  3. double pow(double, double);

1 and 3.


In the following program where is the variable a getting defined and where it is getting declared?

#include
int main()
{
extern int a;
printf("%d\n", a);
return 0;
}
int a=20;

extern int a is declaration, int a = 20 is the definition

When we mention the prototype of a function?

Declaring.

When we mention the prototype of a function?

A function prototype in C or C++ is a declaration of a function that omits the function body but does specify the function's name, argument types and return type. While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface.


.

.

I also find it frustrating when I see unfairness or injustice, whether it's in the workplace or in the broader world. I believe strongly in fairness, equity, and treating others with respect and dignity. When I encounter situations where these principles are not upheld, it can evoke a sense of frustration or disappointment.

That being said, I've learned to channel these emotions constructively by focusing on finding solutions and advocating for positive change. Whether it's through facilitating discussions, providing feedback, or actively working to address underlying issues, I strive to approach challenging situations with a solutions-oriented mindset.

Overall, I believe that acknowledging and understanding our emotions is an important part of being human, but it's equally important to channel them in a constructive and productive manner, especially in a professional setting."

Control Instructions

How many times "q3schools" is get printed?.

#include
int main()
{ int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("q3schools");
}
return 0;
}


"One example of my creativity occurred when I was tasked with [mention a specific project or challenge]. We were facing [describe the problem or objective], and it required a fresh approach to achieve our goals.

Instead of following the traditional methods, I decided to [explain your creative approach or idea]. I brainstormed with the team to generate new ideas, conducted research to gather inspiration from diverse sources, and experimented with different concepts to see what would work best in our situation.

For instance, in one particular brainstorming session, I proposed [describe a specific idea or solution you came up with]. It was unconventional at first, but after refining and testing it, we found that it not only addressed the problem effectively but also exceeded our expectations in terms of results.

What made this approach creative was not just the novelty of the idea itself, but also the process of exploring different possibilities, being open to experimentation, and embracing a mindset of innovation and adaptation.

Ultimately, this experience taught me the value of creativity in problem-solving and the importance of fostering an environment that encourages experimentation and thinking outside the box to achieve success."


This response provides a concrete example of your creativity, demonstrating your ability to approach challenges with innovation and resourcefulness. It's essential to emphasize the process you followed, including brainstorming, research, and experimentation, to showcase your creative thinking skills.

How many times the while loop will get executed if a short int is 2 byte wide?

#include
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0; }

The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop


Which of the following is not logical operator?

&' is not a Logical operator.


In mathematics and computer programming, which is the correct order of mathematical operators ?

Division, Multiplication, Addition, Subtraction

Which of the following cannot be checked in a switch-case statement?

Ethical integrity is paramount in any professional setting. Here's a suggested approach to respond to this question:

Expressions:

Which of the following is the correct order of evaluation for the below expression?

z = x + y * z / 4 % 2 - 1

* / % + - =

Which of the following is the correct usage of conditional operators used in C?

max = a>b ? a>c?a:c:b>c?b:c

Which of the following are unary operators in C?

1, 2, 3

Which of the following correctly shows the hierarchy of arithmetic operations in C?

/ * + -

Which of the following is the correct order if calling functions in the below code? a = f1(23, 14) * f2(12/4) + f3();

Order may vary from compiler to compiler

In which order do the following gets evaluated

  1. Relational
  2. Arithmetic
  3. Logical
  4. Assignment

2134

floating point issues

What are the different types of real data type in C ?

float, double, long double

What will you do to treat the constant 3.14 as a long double?

use 3.14L

Which of the following range is a valid long double (Turbo C in 16 bit DOS OS) ?

3.4E-4932 to 1.1E+493

If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?

#include
#include
int main()
{
float a=5.375;
char *p;
int i;
p = (char*)&a;
for(i=0; i<=3; i++)
printf("%02x\n", (unsigned char)p[i]);
return 0;
}

00 00 AC 40

Which statement will you add in the following program to work it correctly?

#include
int main()
{
printf("%f\n", log(36.0));
return 0;
}

#include

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?

rem = fmod(5.5, 1.3)

We want to round off x, a float, to an int value, The correct way to do is

y = (int)(x + 0.5)

The binary equivalent of 5.375 is

101.011

What will you do to treat the constant 3.14 as a float?

use 3.14f

A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?

Depends on big endian or little endian architecture

Depends on big endian or little endian architecture

C Preprocessor

In which stage the following code #include gets replaced by the contents of the file stdio.h

During preprocessing

What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?

#include
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
int x=10, y=20;
SWAP(x, y, int);
printf("%d %d\n", x, y);
return 0;
}

Not compile

Pointer

Can you combine the following two statements into one?

char *p;
p = (char*) malloc(100);

char *p = (char*)malloc(100);

What is (void*)0?

Representation of NULL pointer

In which header file is the NULL macro defined?

stdio.h and stddef.h

If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?

->

The operator used to get value at address stored in a pointer variable is

*

What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

*(*(*(*(a+i)+j)+k)+l)

A pointer is

A variable that stores address of other variable

How many bytes are occupied by near, far and huge pointers (DOS)?

near=2 far=4 huge=4

Strings

Which of the following function is used to find the first occurrence of a given string in another string?

strstr()

The library function used to find the last occurrence of a character in a string is

strrchr()

How will you print \n on the screen?

printf("\\n");

If the two strings are identical, then strcmp() function returns

0

Which of the following function is correct that finds the length of a string?
int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }
int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); }
int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); }
int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }

int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
{
length++; s++;
}
return (length);
}
Structures, Unions, Enums

What is the similarity between a structure, union and enumeration?

All of them let you define new data types

Command Line Arguments

What do the 'c' and 'v' in argv stands for?

'c' means argument count 'v' means argument vector

The maximum combined length of the command-line arguments including the spaces between adjacent arguments is

It may vary from one operating system to another

According to ANSI specifications which is the correct way of declaring main when it receives command-line arguments?

int main(int argc, char *argv[])
int main(argc, argv)
int argc; char *argv;
int main()
{
int argc; char *argv;
}
int main(int argc, char *argv[])
Arrays

In C, if you pass an array as an argument to a function, what actually gets passed?

Base address of the array

What does the following declaration mean?:int (*ptr)[10];

ptr is a pointer to an array of 10 integers

What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

The program may crash if some important data gets overwritten.




Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML 5

Python

java

C++

C

JavaScript

Campus Learning

C

C#

java